package net.stratusprogramming.school.Game.Battle.GUI;


import java.util.ArrayList;

import net.stratusprogramming.school.Game.Battle.Battle;
import net.stratusprogramming.school.Game.Battle.Menu;
import net.stratusprogramming.school.Game.Framework.Battle.Combatant;
import net.stratusprogramming.school.Game.Framework.Scene.Group;
import net.stratusprogramming.school.Game.Framework.System.Config;
import net.stratusprogramming.school.Game.Framework.System.InstanceMgr;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;

/**
 * A heads up display 
 * 
 * @author Lienau, Dominic Vitello
 * @since 5/10/12
 * @version 0.1
 */
public class HUD extends Group {
	
	/** Handle to battle */
	private Battle battle;
	
	/** User menu */
	private Menu menu;	
	
	/** The health bar for the player */
	private Bar playerHealth;
	/** The mana bar for the player */
	private Bar playerMana;
	/** The health bar for the enemy */
	private Bar enemyHealth;
	/** The mana bar for the enemy */
	private Bar enemyMana;

	/**
	 * Creates a new HUD
     */
	public HUD() {
		battle = InstanceMgr.battle;
		
		// create and add player health bar
		playerHealth = new Bar(new Color(255, 0, 0, 255));
		add(playerHealth);
		playerHealth.setX(10);
		playerHealth.setY(30);
		playerHealth.setWidth(150);
		playerHealth.setHeight(17);
		playerHealth.setValue(50);
		playerHealth.setTotal(100);
		
		// create and add player mana bar
		playerMana = new Bar(new Color(0, 0, 255, 255));
		add(playerMana);	
		playerMana.setX(10);
		playerMana.setY(50);
		playerMana.setWidth(150);
		playerMana.setValue(100);
		playerMana.setTotal(100);
		playerMana.setHeight(17);	
		
		//For enemies
		enemyHealth = new Bar(Color.red);
		add(enemyHealth);
		enemyHealth.setX(560);
		enemyHealth.setY(30);
		enemyHealth.setWidth(150);
		enemyHealth.setHeight(17);
		enemyHealth.setValue(25);
		enemyHealth.setTotal(100);
		
		enemyMana = new Bar(Color.blue);
		add(enemyMana);
		enemyMana.setX(560);
		enemyMana.setY(50);
		enemyMana.setWidth(150);
		enemyMana.setValue(75);
		enemyMana.setTotal(100);
		enemyMana.setHeight(17);
	
		menu = new Menu();
		add(menu);
	}
		
	
	@Override
	public void update(int delta) {
		super.update(delta);

		playerHealth.setValue(battle.getCombatants().get(0).getHealth());
		playerMana.setValue(battle.getCombatants().get(0).getMana());
		
		enemyHealth.setValue(battle.getCombatants().get(1).getHealth());
		enemyMana.setValue(battle.getCombatants().get(1).getHealth());
	}


	@Override
	public void render(Graphics g) {
		// draw overlay
		g.setColor(new Color(0, 0, 0, 255/2));
		g.fillRect(0, 0, Config.WINDOW_WIDTH, 75);
		g.fillRect(0, Config.WINDOW_HEIGHT-125, Config.WINDOW_WIDTH, 125);

		// draw names
		g.setColor(Color.white);
		ArrayList<Combatant> combatants  = battle.getCombatants();
		g.drawString(combatants.get(0).getName(), 10, 10);
		g.drawString(combatants.get(1).getName(), 560, 10);
		//g.drawString(str, x, y)
		
		super.render(g);
	}	
}
